//API 接口
import http from '@/utils/request'

import {type IRes } from '@/interFace/index'

export interface IimangCodeData extends IRes{
  //这三个返回属于公共类型,定义公共类使用继承 IRes
  // host: string;
  // code: number;
  // errorMessage: string;
  data:{
    bigWidth:number;
    bigHeight:number;
    bigImageBase64:string;
    posX:number;
    posY:number;
    smallHeight:number;
    smallWidth:number;
    smallImageBase64:string;
  }

}

// 获取图片验证码
export const getImageCode = (phone:string) => {
  return http.post<IimangCodeData>('/xlx-sso/user/getImageCode', { phone }, {})
}

interface IverifyImageCode extends IRes{
  // host: string;
  // code: number;
  // errorMessage: string;
  data:boolean
}
// 校验滑块图形验证并发送验证码
export const verifyImageCode = (movePosX:string, phone:string) => {
  return http.post<IverifyImageCode>('/xlx-sso/user/verifyImageCode', { movePosX, phone }, {})
}


// interface 定义的同名接口 会合并到一起
interface LoginParams {
  phone: string

  // phone: string
}
//合并时 参数相同  类型不同   会报错  此时phone这个参数类型还是string
interface LoginParams {
  phone: number  //这里不执行这句 因为类型冲突， 接口那边显示的类型还是 number
  password: string
}
//如果是走继承 extends  可以解决冲突  继承类型接口中的参数类型可以被新的接口 重新定义，新接口没有的参数则被继承
interface LoginParams111 extends LoginParams {
  phone: number
  password: number
  verificationCode: string
}

interface loginVerificationOnly extends IRes {
  data: {
    token: string;
    isNew?:boolean
  }
}

// 验证码登录
export const loginVerification = (phone: string, verificationCode: string,) => {
  return http.post<loginVerificationOnly>('/xlx-sso/user/loginVerification', { verificationCode, phone })
}

interface IgetLoginParam extends IRes {
  data:{
    redirectUri: string;
    appid: string;
    scope: string;
    state: string;
  }
}

// 微信扫描登录
export const getLoginParam =()=>{
  return http.get<IgetLoginParam>('/xlx-sso/oauth/wechat/getLoginParam')
}

// 密码登录
interface IloginPwd extends IRes {
  data: {
    user: {
      created: string;//创建时间
      updated: string;//更新时间
      id: number;
      mobile: string;//用户手机号
      password: null;
    },
    token: string ;//token
  }
}
export const loginPwd = (mobile: string, password:string)=>{
  return http.post<IloginPwd>('/xlx-sso/user/login', { mobile,password})
}